import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class test_24_09_08 {
    class Solution01 {
        public String shortestCompletingWord(String licensePlate, String[] words) {
            String result = licensePlate.replaceAll("[\\s\\d]+", "");
            // 得到每一个字符的个数
            int[] charcoll = getchar(result);
            int len = Integer.MAX_VALUE;
            String ans = null;
            for (String word : words) {
                boolean flag = true;
                int[] cur = getchar(word);
                for (int i = 0; i < 26; i++) {
                    if (charcoll[i] > cur[i]) {
                        flag = false;
                        break;
                    }
                }
                if (flag && word.length() < len) {
                    len = word.length();
                    ans = word;
                }
            }
            return ans;
        }

        public int[] getchar(String s) {
            int[] charcoll = new int[26];
            for (char c : s.toCharArray()) {
                charcoll[Character.toLowerCase(c) - 'a']++;
            }
            return charcoll;
        }
    }


    class Solution02 {
        public String convertDateToBinary(String date) {
            StringBuilder sb = new StringBuilder();
            String[] dats = date.split("-");
            for (int i = 0; i < 3; i++) {
                String s = "";
                int x = Integer.valueOf(dats[i]);
                while (x > 0) {
                    s = (x % 2) + s;
                    x /= 2;
                }
                if (i > 0) {
                    sb.append("-");
                }
                sb.append(s);
            }
            return sb.toString();
        }
    }


    /* 键值对 */
    class Pair {
        public int key;
        public String val;

        public Pair(int key, String val) {
            this.key = key;
            this.val = val;
        }
    }

    /* 基于数组实现的哈希表 */
    class ArrayHashMap {
        private List<Pair> buckets;

        public ArrayHashMap() {
            // 初始化数组，包含 100 个桶
            buckets = new ArrayList<>();
            for (int i = 0; i < 100; i++) {
                buckets.add(null);
            }
        }

        /* 哈希函数 */
        private int hashFunc(int key) {
            int index = key % 100;
            return index;
        }

        /* 查询操作 */
        public String get(int key) {
            int index = hashFunc(key);
            Pair pair = buckets.get(index);
            if (pair == null)
                return null;
            return pair.val;
        }

        /* 添加操作 */
        public void put(int key, String val) {
            Pair pair = new Pair(key, val);
            int index = hashFunc(key);
            buckets.set(index, pair);
        }

        /* 删除操作 */
        public void remove(int key) {
            int index = hashFunc(key);
            // 置为 null ，代表删除
            buckets.set(index, null);
        }

        /* 获取所有键值对 */
        public List<Pair> pairSet() {
            List<Pair> pairSet = new ArrayList<>();
            for (Pair pair : buckets) {
                if (pair != null)
                    pairSet.add(pair);
            }
            return pairSet;
        }

        /* 获取所有键 */
        public List<Integer> keySet() {
            List<Integer> keySet = new ArrayList<>();
            for (Pair pair : buckets) {
                if (pair != null)
                    keySet.add(pair.key);
            }
            return keySet;
        }

        /* 获取所有值 */
        public List<String> valueSet() {
            List<String> valueSet = new ArrayList<>();
            for (Pair pair : buckets) {
                if (pair != null)
                    valueSet.add(pair.val);
            }
            return valueSet;
        }

        /* 打印哈希表 */
        public void print() {
            for (Pair kv : pairSet()) {
                System.out.println(kv.key + " -> " + kv.val);
            }
        }
    }


}
